﻿Public Class CodePegRow

    Private codeRow(3) As String

    Private Sub CodePegRow_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Disable()
    End Sub

    Public Function GetCodeRow() As String()
        Return codeRow
    End Function

    Public Sub Enable()
        PictureBox1.AllowDrop = True
        PictureBox2.AllowDrop = True
        PictureBox3.AllowDrop = True
        PictureBox4.AllowDrop = True
    End Sub

    Public Sub Disable()
        PictureBox1.AllowDrop = False
        PictureBox2.AllowDrop = False
        PictureBox3.AllowDrop = False
        PictureBox4.AllowDrop = False
    End Sub

    Public Sub InitializeCodePegRow()
        PictureBox1.Load("artwork\gray.png")
        codeRow(0) = GetImageName(PictureBox1.ImageLocation)
        PictureBox2.Load("artwork\gray.png")
        codeRow(1) = GetImageName(PictureBox2.ImageLocation)
        PictureBox3.Load("artwork\gray.png")
        codeRow(2) = GetImageName(PictureBox3.ImageLocation)
        PictureBox4.Load("artwork\gray.png")
        codeRow(3) = GetImageName(PictureBox4.ImageLocation)
    End Sub

    Private Function GetImageName(ByVal location As String) As String
        Dim firstSplit() As String = location.Split(New Char() {"\"c})

        Dim secondSplit() As String = firstSplit(1).Split(New Char() {"."c})

        Return secondSplit(0)
    End Function

    Public Sub SetColor(ByVal id As Integer, ByVal color As String)
        If id = 0 Then
            PictureBox1.Load("artwork\" + color + ".png")
        ElseIf id = 1 Then
            PictureBox2.Load("artwork\" + color + ".png")
        ElseIf id = 2 Then
            PictureBox3.Load("artwork\" + color + ".png")
        ElseIf id = 3 Then
            PictureBox4.Load("artwork\" + color + ".png")
        End If
    End Sub

    Private Sub PictureBox1_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles PictureBox1.DragDrop
        ' Assign the image to the PictureBox.
        PictureBox1.Image = e.Data.GetData(DataFormats.Bitmap)
        If CodeMaker.Visible Then
            codeRow(0) = GetImageName(CodeMaker.CodePegList1.GetLastUsed.ImageLocation)
        Else
            codeRow(0) = GetImageName(CodeBreaker.CodePegList1.GetLastUsed.ImageLocation)
        End If
    End Sub

    Private Sub PictureBox1_DragEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles PictureBox1.DragEnter
        If e.Data.GetDataPresent(DataFormats.Bitmap) Then
            e.Effect = DragDropEffects.Copy
        Else
            e.Effect = DragDropEffects.None
        End If
    End Sub

    Private Sub PictureBox2_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles PictureBox2.DragDrop
        ' Assign the image to the PictureBox.
        PictureBox2.Image = e.Data.GetData(DataFormats.Bitmap)
        If CodeMaker.Visible Then
            codeRow(1) = GetImageName(CodeMaker.CodePegList1.GetLastUsed.ImageLocation)
        Else
            codeRow(1) = GetImageName(CodeBreaker.CodePegList1.GetLastUsed.ImageLocation)
        End If
    End Sub

    Private Sub PictureBox2_DragEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles PictureBox2.DragEnter
        If e.Data.GetDataPresent(DataFormats.Bitmap) Then
            e.Effect = DragDropEffects.Copy
        Else
            e.Effect = DragDropEffects.None
        End If
    End Sub

    Private Sub PictureBox3_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles PictureBox3.DragDrop
        ' Assign the image to the PictureBox.
        PictureBox3.Image = e.Data.GetData(DataFormats.Bitmap)
        If CodeMaker.Visible Then
            codeRow(2) = GetImageName(CodeMaker.CodePegList1.GetLastUsed.ImageLocation)
        Else
            codeRow(2) = GetImageName(CodeBreaker.CodePegList1.GetLastUsed.ImageLocation)
        End If
    End Sub

    Private Sub PictureBox3_DragEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles PictureBox3.DragEnter
        If e.Data.GetDataPresent(DataFormats.Bitmap) Then
            e.Effect = DragDropEffects.Copy
        Else
            e.Effect = DragDropEffects.None
        End If
    End Sub

    Private Sub PictureBox4_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles PictureBox4.DragDrop
        ' Assign the image to the PictureBox.
        PictureBox4.Image = e.Data.GetData(DataFormats.Bitmap)
        If CodeMaker.Visible Then
            codeRow(3) = GetImageName(CodeMaker.CodePegList1.GetLastUsed.ImageLocation)
        Else
            codeRow(3) = GetImageName(CodeBreaker.CodePegList1.GetLastUsed.ImageLocation)
        End If
    End Sub

    Private Sub PictureBox4_DragEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles PictureBox4.DragEnter
        If e.Data.GetDataPresent(DataFormats.Bitmap) Then
            e.Effect = DragDropEffects.Copy
        Else
            e.Effect = DragDropEffects.None
        End If
    End Sub

End Class
